// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Web Risk API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_webrisk_v1::client::WebRiskService;
/// let client = WebRiskService::builder().build().await?;
/// // use `client` to make requests to the Web Risk API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Web Risk API defines an interface to detect malicious URLs on your
/// website and in client applications.
///
/// # Configuration
///
/// To configure `WebRiskService` use the `with_*` methods in the type returned
/// by [builder()][WebRiskService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://webrisk.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::web_risk_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::web_risk_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `WebRiskService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `WebRiskService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct WebRiskService {
    inner: std::sync::Arc<dyn super::stub::dynamic::WebRiskService>,
}

impl WebRiskService {
    /// Returns a builder for [WebRiskService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_webrisk_v1::client::WebRiskService;
    /// let client = WebRiskService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::web_risk_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::web_risk_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::WebRiskService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::WebRiskService>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::WebRiskService> {
        super::transport::WebRiskService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::WebRiskService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::WebRiskService::new)
    }

    /// Gets the most recent threat list diffs. These diffs should be applied to
    /// a local database of hashes to keep it up-to-date. If the local database is
    /// empty or excessively out-of-date, a complete snapshot of the database will
    /// be returned. This Method only updates a single ThreatList at a time. To
    /// update multiple ThreatList databases, this method needs to be called once
    /// for each list.
    pub fn compute_threat_list_diff(
        &self,
    ) -> super::builder::web_risk_service::ComputeThreatListDiff {
        super::builder::web_risk_service::ComputeThreatListDiff::new(self.inner.clone())
    }

    /// This method is used to check whether a URI is on a given threatList.
    /// Multiple threatLists may be searched in a single query.
    /// The response will list all requested threatLists the URI was found to
    /// match. If the URI is not found on any of the requested ThreatList an
    /// empty response will be returned.
    pub fn search_uris(&self) -> super::builder::web_risk_service::SearchUris {
        super::builder::web_risk_service::SearchUris::new(self.inner.clone())
    }

    /// Gets the full hashes that match the requested hash prefix.
    /// This is used after a hash prefix is looked up in a threatList
    /// and there is a match. The client side threatList only holds partial hashes
    /// so the client must query this method to determine if there is a full
    /// hash match of a threat.
    pub fn search_hashes(&self) -> super::builder::web_risk_service::SearchHashes {
        super::builder::web_risk_service::SearchHashes::new(self.inner.clone())
    }

    /// Creates a Submission of a URI suspected of containing phishing content to
    /// be reviewed. If the result verifies the existence of malicious phishing
    /// content, the site will be added to the [Google's Social Engineering
    /// lists](https://support.google.com/webmasters/answer/6350487/) in order to
    /// protect users that could get exposed to this threat in the future. Only
    /// allowlisted projects can use this method during Early Access. Please reach
    /// out to Sales or your customer engineer to obtain access.
    pub fn create_submission(&self) -> super::builder::web_risk_service::CreateSubmission {
        super::builder::web_risk_service::CreateSubmission::new(self.inner.clone())
    }

    /// Submits a URI suspected of containing malicious content to be reviewed.
    /// Returns a google.longrunning.Operation which, once the review is complete,
    /// is updated with its result. You can use the [Pub/Sub API]
    /// (<https://cloud.google.com/pubsub>) to receive notifications for the returned
    /// Operation. If the result verifies the existence of malicious content, the
    /// site will be added to the [Google's Social Engineering lists]
    /// (<https://support.google.com/webmasters/answer/6350487/>) in order to
    /// protect users that could get exposed to this threat in the future. Only
    /// allowlisted projects can use this method during Early Access. Please reach
    /// out to Sales or your customer engineer to obtain access.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn submit_uri(&self) -> super::builder::web_risk_service::SubmitUri {
        super::builder::web_risk_service::SubmitUri::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::web_risk_service::ListOperations {
        super::builder::web_risk_service::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::web_risk_service::GetOperation {
        super::builder::web_risk_service::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn delete_operation(&self) -> super::builder::web_risk_service::DeleteOperation {
        super::builder::web_risk_service::DeleteOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::web_risk_service::CancelOperation {
        super::builder::web_risk_service::CancelOperation::new(self.inner.clone())
    }
}
